import { _decorator, Component, Label, Node } from 'cc';
import { UIBase } from '../../FrameWork3.8.6/FrameWork/UIFramework/UIBase';
import { LevelDetails } from '../../FrameWork3.8.6/FrameWork/Common/CommonInterface';
import { BundleConfig } from '../../FrameWork3.8.6/FrameWork/NeedToChange/BundleConfig';
import { UIUtils } from '../../FrameWork3.8.6/FrameWork/UIFramework/UIUtils';
import { GameManager } from '../Game/Manager/GameManager';
const { ccclass, property } = _decorator;

@ccclass('LevelDetailsPanel')
export class LevelDetailsPanel extends UIBase {
    //当前关卡的数据信息
    private _levelDetails:LevelDetails=null;

    //需要传给开始游戏后场景的数据
    private _gameArgs={
        "task":[],
        "requirements":[],
        "enemyID":[],
    }
    onInit(...rest: any[]): void {
        //注册关闭按钮的方法
        this.addClickEventListener("_CloseBtn",()=>{
            this.closeSelf();
        })
        //初始化当前页面的信息
        this.updateData(rest[0] as LevelDetails);
        //注册开始游戏的方法
        this.addClickEventListener("_StartBtn",()=>{
            //保存当前关卡的道具ID
            GameManager.instance.propID=rest[1];
            for(let key in this._gameArgs){
                this._gameArgs[key]=UIUtils.deepClone(this._levelDetails[key]);
            }
            this._gameArgs["levelName"]=this._levelDetails.levelName;
            this.openUI("MainUI",true,true,BundleConfig.UI.name,"Widget",this._gameArgs);
            this.closeUI("LevelPanel");
            this.closeUI("Menu");
        })
    }

    onEnter(...rest: any[]): void {
        //每一次打开当前页面都需要更新信息
        this.updateData(rest[0] as LevelDetails);
    }
    
    //更新当前页面信息的方法
    updateData(levelDetails:LevelDetails){
        //将当前关卡信息存储起来
        this._levelDetails=levelDetails;
        this.getComp<Label>("_LevelNameLabel","Label").string=this._levelDetails.levelName;
        this.getComp<Label>("_LevelDescriptionLabel","Label").string=this._levelDetails.description;
    }
    
}


